from marshmallow import fields

from utils.messages.serializers import RequestMessageHeader, ResponseMessageHeader
# 设备cpu负载
from utils.messages.validators import ResultCodeValidator


class SnowFlakeRequest(RequestMessageHeader):
    count = fields.Int()

    class Meta:
        MSG_TYPE = 0


class SnowFlakeResponse(ResponseMessageHeader):
    data = fields.List(fields.Int)

    class Meta:
        MSG_TYPE = 1


class MultiDeviceCpuLoadRequest(RequestMessageHeader):
    device_id = fields.Int()
    size = fields.Int(min_value=1, max_value=1000)

    class Meta:
        MSG_TYPE = 1001


class MultiDeviceCpuLoadResponse(ResponseMessageHeader):
    """
    result_code
    """

    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(validators=[ResultCodeValidator(ResultCode)])

    class Meta:
        MSG_TYPE = 1002


class LatestDeviceCpuLoadRequest(RequestMessageHeader):
    device_id = fields.Int()

    class Meta:
        MSG_TYPE = 1003


class LatestDeviceCpuLoadResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 1004


# 设备cpu状态


class MultiDeviceCpuStatusRequest(RequestMessageHeader):
    device_id = fields.Int()
    size = fields.Int(min_value=1, max_value=1000)

    class Meta:
        MSG_TYPE = 1005


class MultiDeviceCpuStatusResponse(ResponseMessageHeader):
    """
    result_code
    """

    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(validators=[ResultCodeValidator(ResultCode)])

    class Meta:
        MSG_TYPE = 1006


class LatestDeviceCpuStatusRequest(RequestMessageHeader):
    device_id = fields.Int()

    class Meta:
        MSG_TYPE = 1007


class LatestDeviceCpuStatusResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 1008


# 设备硬盘IO


class MultiDeviceDiskIORequest(RequestMessageHeader):
    device_id = fields.Int()
    size = fields.Int(min_value=1, max_value=1000)

    class Meta:
        MSG_TYPE = 1009


class MultiDeviceDiskIOResponse(ResponseMessageHeader):
    """
    result_code
    """

    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(validators=[ResultCodeValidator(ResultCode)])

    class Meta:
        MSG_TYPE = 10010


class LatestDeviceDiskIORequest(RequestMessageHeader):
    device_id = fields.Int()

    class Meta:
        MSG_TYPE = 10011


class LatestDeviceDiskIOResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 10012


# 设备内存状态


class MultiDeviceMemoryStatusRequest(RequestMessageHeader):
    device_id = fields.Int()
    size = fields.Int(min_value=1, max_value=1000)

    class Meta:
        MSG_TYPE = 10013


class MultiDeviceMemoryStatusResponse(ResponseMessageHeader):
    """
    result_code
    """

    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(validators=[ResultCodeValidator(ResultCode)])

    class Meta:
        MSG_TYPE = 10014


class LatestDeviceMemoryStatusRequest(RequestMessageHeader):
    device_id = fields.Int()

    class Meta:
        MSG_TYPE = 10015


class LatestDeviceMemoryStatusResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 10016


# 设备网卡状态


class MultiDeviceNetworkCardStatusRequest(RequestMessageHeader):
    device_id = fields.Int()
    size = fields.Int(min_value=1, max_value=1000)

    class Meta:
        MSG_TYPE = 10017


class MultiDeviceNetworkCardStatusResponse(ResponseMessageHeader):
    """
    result_code
    """

    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(validators=[ResultCodeValidator(ResultCode)])

    class Meta:
        MSG_TYPE = 10018


class LatestDeviceNetworkCardStatusRequest(RequestMessageHeader):
    device_id = fields.Int()

    class Meta:
        MSG_TYPE = 10019


class LatestDeviceNetworkCardStatusResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 10020


# 设备上的服务


class ServiceOnDeviceRequest(RequestMessageHeader):
    device_id = fields.Int()

    class Meta:
        MSG_TYPE = 10021


class ServiceOnDeviceResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        SERVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(validators=[ResultCodeValidator(ResultCode)])

    class Meta:
        MSG_TYPE = 10022


# 服务运行数据


class LatestServiceRunningDataRequest(RequestMessageHeader):
    service_id = fields.Int()

    class Meta:
        MSG_TYPE = 10023


class LatestServiceRunningDataResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        SERVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 10024


class MultiServiceRunningDataRequest(RequestMessageHeader):
    service_id = fields.Int()
    size = fields.Int(min_value=1, max_value=1000)

    class Meta:
        MSG_TYPE = 10025


class MultiServiceRunningDataResponse(ResponseMessageHeader):
    """
    result_code
    """

    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        SERVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(validators=[ResultCodeValidator(ResultCode)])

    class Meta:
        MSG_TYPE = 10026


# 设备硬盘使用率


class MultiDevicePartitionStatusRequest(RequestMessageHeader):
    device_id = fields.Int()
    size = fields.Int(min_value=1, max_value=1000)

    class Meta:
        MSG_TYPE = 10027


class MultiDevicePartitionStatusResponse(ResponseMessageHeader):
    """
    result_code
    """

    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(validators=[ResultCodeValidator(ResultCode)])

    class Meta:
        MSG_TYPE = 10028


class LatestDevicePartitionStatusRequest(RequestMessageHeader):
    device_id = fields.Int()

    class Meta:
        MSG_TYPE = 10029


class LatestDevicePartitionStatusResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 10030


class LatestDeviceProcessStatusRequest(RequestMessageHeader):
    device_id = fields.Int()

    class Meta:
        MSG_TYPE = 10031


class LatestDeviceProcessStatusResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 10032


class MultiDeviceProcessStatusRequest(RequestMessageHeader):
    device_id = fields.Int()
    size = fields.Int()

    class Meta:
        MSG_TYPE = 10033


class MultiDeviceProcessStatusResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        DEVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.String(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 10034


class LatestBusinessDataRequest(RequestMessageHeader):
    service_id = fields.Int()
    statfield_id = fields.Int()

    class Meta:
        MSG_TYPE = 4001


class LatestBusinessDataResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        SERVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.Str(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 4002


class MultiBusinessDataRequest(RequestMessageHeader):
    service_id = fields.Int()
    statfield_id = fields.Int()
    size = fields.Int(min_value=1, max_value=1000)

    class Meta:
        MSG_TYPE = 4003


class MultiBusinessDataResponse(ResponseMessageHeader):
    """
    result_code
    """

    class ResultCode:
        NORMAL = 0
        NO_DATA = 1
        SERVICE_NOT_FOUND = 2
        ILLEGAL_PARAMS = 3
        ERROR = 100

    data = fields.List(fields.Dict, required=False)
    errors = fields.Dict(required=False)
    desc = fields.Str(required=False)
    result_code = fields.Int(validators=[ResultCodeValidator(ResultCode)])

    class Meta:
        MSG_TYPE = 4004


class ServerTimeRequest(RequestMessageHeader):
    class Meta:
        MSG_TYPE = 3001


class ServerTimeResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        ERROR = 100

    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )
    time = fields.Int()

    class Meta:
        MSG_TYPE = 3002


class UserPingRequest(RequestMessageHeader):
    token = fields.Str()

    class Meta:
        MSG_TYPE = 3003


class UserPingResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        ANTHER_LOGIN = 1
        ERROR = 100

    desc = fields.Str(required=False)
    time = fields.Int()
    errors = fields.Dict(required=False)
    result_code = fields.Int(
        validators=[
            ResultCodeValidator(ResultCode)
        ]
    )

    class Meta:
        MSG_TYPE = 3004


class AppUpgradeResultResponse(ResponseMessageHeader):
    data = fields.Str(allow_null=True, required=False)
    result = fields.Int()

    class Meta:
        MSG_TYPE = 2006


class ServiceConfigChangeResultResponse(ResponseMessageHeader):
    data = fields.Str()
    result = fields.Int()

    class Meta:
        MSG_TYPE = 2008


class DeviceActivateResponse(ResponseMessageHeader):
    status_code = fields.Int()
    msg = fields.Str()

    class Meta:
        MSG_TYPE = 2010


class BatchRestartAgentServiceResponse(ResponseMessageHeader):
    status_code = fields.Int()
    msg = fields.Str()

    class Meta:
        MSG_TYPE = 2012


class ChangeServiceConfigResponse(ResponseMessageHeader):
    class ResultCode:
        NORMAL = 0
        ERROR = 100

    data = fields.Str(allow_null=True, required=False)
    result = fields.Int()

    class Meta:
        MSG_TYPE = 10036


class LogTailerStreamResponse(ResponseMessageHeader):
    data = fields.Str()

    class Meta:
        MSG_TYPE = 2007
